# -*- python -*-
# ex: set syntax=python:

# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This is the buildmaster config file for the 'libvpx' bot. It must
# be installed as 'master.cfg' in your buildmaster's base directory
# (although the filename can be changed with the --basedir option to
# 'mktap buildbot master').

# It has one job: define a dictionary named BuildmasterConfig. This
# dictionary has a variety of keys to control different aspects of the
# buildmaster. They are documented in docs/config.xhtml .


from buildbot.changes.gitpoller import GitPoller
from buildbot.scheduler import Scheduler
from buildbot.schedulers.filter import ChangeFilter

from common import chromium_utils
from master import master_utils
from master import slaves_list
from master.factory import annotator_factory

import config
import master_site_config

ActiveMaster = master_site_config.Libvpx

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

# 'slavePortnum' defines the TCP port to listen on. This must match the value
# configured into the buildslaves (with their --master option)
c['slavePortnum'] = ActiveMaster.slave_port

# Disable compression for the stdio files.
c['logCompressionLimit'] = False

# Load the list of slaves.
slaves = slaves_list.SlavesList('slaves.cfg', 'Libvpx')

config.DatabaseSetup(c, require_dbconfig=ActiveMaster.is_production_host)

####### CHANGESOURCES
if ActiveMaster.is_production_host:
  libvpx_poller = GitPoller(repourl=ActiveMaster.source_url,
                            gitbin=chromium_utils.GIT_BIN,
                            branch='master',
                            workdir='gitpoller/public',
                            category='public',
                            pollinterval=5*60)
  c['change_source'] = [libvpx_poller]

####### SCHEDULERS

repo_filter = ChangeFilter(category='public')

libvpx_linux_scheduler = Scheduler(name='public linux scheduler',
                             treeStableTimer=60,
                             change_filter=repo_filter,
                             builderNames=['Linux Builder'])

libvpx_nexus_5_scheduler = Scheduler(name='public nexus 5 scheduler',
                             treeStableTimer=60,
                             change_filter=repo_filter,
                             builderNames=['Nexus 5 Builder'])

libvpx_nexus_7_scheduler = Scheduler(name='public nexus 7 scheduler',
                             treeStableTimer=60,
                             change_filter=repo_filter,
                             builderNames=['Nexus 7 Builder'])

c['schedulers'] = [
      libvpx_linux_scheduler,
      libvpx_nexus_7_scheduler,
      libvpx_nexus_5_scheduler
]

####### BUILDERS

# buildbot/process/factory.py provides several BuildFactory classes you can
# start with, which implement build processes for common targets (GNU
# autoconf projects, CPAN perl modules, etc). The factory.BuildFactory is the
# base class, and is configured with a series of BuildSteps. When the build
# is run, the appropriate buildslave is told to execute each Step in turn.

# the first BuildStep is typically responsible for obtaining a copy of the
# sources. There are source-obtaining Steps in buildbot/process/step.py for
# CVS, SVN, and others.

builders = []

# ----------------------------------------------------------------------------
# FACTORIES

android_factory = annotator_factory.AnnotatorFactory().BaseFactory(
    'libvpx/android_unittests',
    {
      'TARGET_BITS': 64,
      'perf_id': 'linux-release',
      'libvpx_git_url' : ActiveMaster.source_url,
    })

linux_factory = annotator_factory.AnnotatorFactory().BaseFactory(
    'libvpx/unittests',
    {
      'TARGET_BITS': 64,
      'perf_id': 'linux-release',
      'libvpx_git_url' : ActiveMaster.source_url,
    })

# ----------------------------------------------------------------------------
# BUILDER DEFINITIONS

# The 'builders' list defines the Builders. Each one is configured with a
# dictionary, using the following keys:
#  name (required): the name used to describe this bilder
#  builddir (required): which subdirectory to run the builder in
#  factory (required): a BuildFactory to define how the build is run
#  periodicBuildTime (optional): if set, force a build every N seconds
#  category (optional): it is not used in the normal 'buildbot' meaning. It is
#                       used by gatekeeper to determine which steps it should
#                       look for to close the tree.
#

b_libvpx_linux_builder = {
    'name': 'Linux Builder',
    'builddir': 'libvpx-linux',
    'factory': linux_factory,
    'auto_reboot': False,
}

b_libvpx_nexus_5_builder = {
    'name': 'Nexus 5 Builder',
    'builddir': 'libvpx-nexus-5',
    'factory': android_factory,
    'auto_reboot': False,
}

b_libvpx_nexus_7_builder = {
    'name': 'Nexus 7 Builder',
    'builddir': 'libvpx-nexus-7',
    'factory': android_factory,
    'auto_reboot': False,
}

c['builders'] = [
     b_libvpx_linux_builder,
     b_libvpx_nexus_5_builder,
     b_libvpx_nexus_7_builder
]

####### BUILDSLAVES

# Associate the slaves to the manual builders. The configuration is in
# slaves.cfg.
for builder in c['builders']:
  builder['slavenames'] = slaves.GetSlavesName(builder=builder['name'])

# The 'slaves' list defines the set of allowable buildslaves. List all the
# slaves registered to a builder. Remove dupes.
c['slaves'] = master_utils.AutoSetupSlaves(c['builders'],
                                           config.Master.GetBotPassword())
master_utils.VerifySetup(c, slaves)


####### STATUS TARGETS

# The 'buildbotURL' string should point to the location where the buildbot's
# internal web server (usually the html.Waterfall page) is visible. This
# typically uses the port number set in the Waterfall 'status' entry, but
# with an externally-visible host name which the buildbot cannot figure out
# without some help.

# Must come before AutoSetupMaster().
c['buildbotURL'] = ActiveMaster.buildbot_url

# Adds common status and tools to this master.
master_utils.AutoSetupMaster(c, ActiveMaster,
    public_html='../master.chromium/public_html',
    templates=['../master.chromium/templates'],
    enable_http_status_push=ActiveMaster.is_production_host)

####### PROJECT IDENTITY

# the 'projectName' string will be used to describe the project that this
# buildbot is working on. For example, it is used as the title of the
# waterfall HTML page. The 'projectURL' string will be used to provide a link
# from buildbot HTML pages to your project's home page.

c['projectName'] = ActiveMaster.project_name
c['projectURL'] = config.Master.project_url
